package net.UDPChat;

import java.net.*;
import java.util.Scanner;

public class UDPClient {

    public static void main(String[] args) throws Exception {

        //客户端也有自己的Socket
        DatagramSocket clientSocket = new DatagramSocket(8888);
        System.out.println("客户端已启动");

        byte[] message;
        Scanner scanner = new Scanner(System.in);
        while(true){
            //直接把读到的内容变成字节数组的形式放在message中
            message = scanner.nextLine().getBytes();
            //把数据封装成一个数据包
            DatagramPacket sendMessage = new DatagramPacket(
                    message,
                    message.length,
                    InetAddress.getLocalHost(),
                    9999
            );
            //把数据包扔出去，由服务端解析
            clientSocket.send(sendMessage);

        }
    }
}
